﻿using SlamDunk.CMS.Model.Base;
using SlamDunk.CMS.Model.FormatModel;
using SlamDunk.CMS.Model.ViewModel;

namespace SlamDunk.CMS.Model.DataModel
{
    /// <summary>
    /// 菜单
    /// </summary>
    public class Menus : BaseEntity
    {
        #region # 属性

        #region 上级菜单Id —— int PId
        /// <summary>
        /// 上级菜单Id
        /// </summary>
        public int PId { get; set; }
        #endregion

        #region 菜单名称 —— string MenuName
        /// <summary>
        /// 菜单名称
        /// </summary>
        public string MenuName { get; set; }
        #endregion

        #region 链接地址 —— string Url
        /// <summary>
        /// 链接地址
        /// </summary>
        public string Url { get; set; }
        #endregion

        #region 是否是链接 —— bool? IsLink
        /// <summary>
        /// 是否是链接
        /// </summary>
        public bool? IsLink { get; set; }
        #endregion

        #region 等级 —— int Level
        /// <summary>
        /// 等级
        /// </summary>
        public int Level { get; set; }
        #endregion

        #region 排序 —— int? Sort
        /// <summary>
        /// 排序
        /// </summary>
        public int? Sort { get; set; }
        #endregion

        #region 图标 —— string Ico
        /// <summary>
        /// 图标
        /// </summary>
        public string Ico { get; set; }
        #endregion

        #endregion

        #region # 方法

        #region 转换为视图模型 —— MenusView ToViewModel()
        /// <summary>
        /// 转换为视图模型
        /// </summary>
        /// <returns>视图模型</returns>
        public MenusView ToViewModel()
        {
            return new MenusView()
            {
                Id = this.Id,
                PId = this.PId,
                MenuName = this.MenuName,
                Url = this.Url,
                IsLink = this.IsLink,
                Level = this.Level,
                Sort = this.Sort,
                Ico = this.Ico
            };
        }
        #endregion

        #region 转换为树形节点 —— TreeModel ToTreeNode()
        /// <summary>
        /// 转换为树形节点
        /// </summary>
        /// <returns>树形节点</returns>
        public TreeModel ToTreeNode()
        {
            //返回TreeModel
            return new TreeModel()
            {
                id = this.Id,
                text = this.MenuName,
                state = "open",
                attributes = new { href = this.Url, isLink = this.IsLink == true ? 1 : 0 },
                @checked = false
            };
        }
        #endregion

        #endregion
    }
}
